package com.loveling.controller;

import com.loveling.entity.Demo;
import com.loveling.service.DemoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created by liang on 2017/5/31.
 */
@RestController
@RequestMapping("/demo")
public class DemoController {

    @Resource
    private DemoService demoService;


    /**
     * @return
     * @visitAddress http://127.0.0.1:8080/demo/save
     */
    @RequestMapping("/save")
    public String save() {
        Demo demo = new Demo();
        demo.setName("liangjiefa");
        demoService.save(demo);
        return "ok.DemoController.save";
    }


    /**
     * @param id
     * @return
     * @visitAddress http://127.0.0.1:8080/demo/getById?id=1
     */
    @GetMapping("/getById")
    public Demo getById(long id) {
        return demoService.getById(id);
    }

}
